package service

import (
	"gin-vue-admin/global"
	"gin-vue-admin/model"
	"gin-vue-admin/model/request"
)

//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateIdCardDecode
//@description: 创建IdCardDecode记录
//@param: idCardDecode model.IdCardDecode
//@return: err error

func CreateIdCardDecode(idCardDecode model.IdCardDecode) (err error) {
	err = global.GVA_DB.Create(&idCardDecode).Error
	return err
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteIdCardDecode
//@description: 删除IdCardDecode记录
//@param: idCardDecode model.IdCardDecode
//@return: err error

func DeleteIdCardDecode(idCardDecode model.IdCardDecode) (err error) {
	err = global.GVA_DB.Delete(idCardDecode).Error
	return err
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteIdCardDecodeByIds
//@description: 批量删除IdCardDecode记录
//@param: ids request.IdsReq
//@return: err error

func DeleteIdCardDecodeByIds(ids request.IdsReq) (err error) {
	err = global.GVA_DB.Delete(&[]model.IdCardDecode{},"id in ?",ids.Ids).Error
	return err
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateIdCardDecode
//@description: 更新IdCardDecode记录
//@param: idCardDecode *model.IdCardDecode
//@return: err error

func UpdateIdCardDecode(idCardDecode model.IdCardDecode) (err error) {
	err = global.GVA_DB.Save(&idCardDecode).Error
	return err
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetIdCardDecode
//@description: 根据id获取IdCardDecode记录
//@param: id uint
//@return: err error, idCardDecode model.IdCardDecode

func GetIdCardDecode(id uint) (err error, idCardDecode model.IdCardDecode) {
	err = global.GVA_DB.Where("id = ?", id).First(&idCardDecode).Error
	return
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetIdCardDecodeInfoList
//@description: 分页获取IdCardDecode记录
//@param: info request.IdCardDecodeSearch
//@return: err error, list interface{}, total int64

func GetIdCardDecodeInfoList(info request.IdCardDecodeSearch) (err error, list interface{}, total int64) {
	limit := info.PageSize
	offset := info.PageSize * (info.Page - 1)
    // 创建db
	db := global.GVA_DB.Model(&model.IdCardDecode{})
    var idCardDecodes []model.IdCardDecode
    // 如果有条件搜索 下方会自动创建搜索语句
	err = db.Count(&total).Error
	err = db.Limit(limit).Offset(offset).Find(&idCardDecodes).Error
	return err, idCardDecodes, total
}